//
//  QIncomeVC.m
//  QoilPublic
//
//  Created by 杨凯 on 16/8/16.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QIncomeVC.h"
#import "QEditChargeCell.h"
#import "QKeyBoardView.h"
#import "QInputMoneyVC.h"
#import "QPayOutChargeTypeVC.h"
#import "QIncomeChargeType.h"
#import "QMoneyAccountVC.h"
#import "QChooseDateVC.h"
#import "QChargeBookDB.h"
@interface QIncomeVC ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)UITextField *textField;

@end

@implementation QIncomeVC{

    QKeyBoardView *_keyBoardView;
    NSArray *_titleArr;
    NSMutableString *c;
    UILabel *_timeLabel;
    
    NSString *_yearMonthISeq;//修改数据时用到，比较数据是不是跨月修改
    
    BOOL _isBack;
    int addIndex;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _titleArr = @[@"1",@"2",@"3",@"",@"4",@"5",@"6",@"",@"7",@"8",@"9",@"",@".",@"0",@"",@""];
    [self setupForDismissKeyboard];//释放键盘
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifishowAction) name:kNotificationKeyBoardShowA object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifinotshowAction) name:kNotificationKeyBoardNotShowA object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}

- (void)setComeStyle:(QIncomeVCStyle)comeStyle{
    _comeStyle = comeStyle;
    [self initData];
    [self createTableView];
    [self createUI];
    WS(wSelf);
    _keyBoardView = [[QKeyBoardView alloc] initWithFrame:CGRectMake(-1, kScreenHeight-200, kScreenWidth+2, 200) andBlock:^(NSInteger tag) {
        [wSelf keyboardIndex:tag];
    }];
    [self.view addSubview:_keyBoardView];
}

#pragma mark --- 初始化数据
- (void)initData{
    _str = _str?_str:@"";
    _typeStr = _typeStr?_typeStr:@"工程款";
    _typeId = _typeId?_typeId:@"1";
    _moneyStr = _moneyStr?_moneyStr:@"现金";
    _moneyId = _moneyId?_moneyId:@"1";
    _week = _week?_week:[QChargeBookDB currentWeek];
    
    NSDateFormatter *datefot = [[NSDateFormatter alloc] init];
    datefot.dateFormat = @"YYYY/MM-dd HH:mm";
    [self formatDate:[datefot stringFromDate:[NSDate date]]];
    NSTimeInterval inter = [[NSDate date] timeIntervalSince1970] * 1000;//当前时间戳
    _createTime = _createTime?_createTime:[NSString stringWithFormat:@"%.f",inter];
    _accountIdStr = _accountIdStr?_accountIdStr:@"";//id如果从下面传过来，则id是不能变的 所以id不能在下面重新赋值   注:如果点了保存再记的话，页面不返回，要重新生成一个id ,所以在点击保存的时候成id
    _descStr = _descStr?_descStr:@"";
    
    if(_comeStyle == QIncomeVCHaveDataStyle){//表示修改数据
        _yearMonthISeq = [NSString stringWithFormat:@"%@%@",_year,_month];
    }
}

#pragma mark --- 键盘同步
- (void)notifishowAction{
    [UIView animateWithDuration:0.35 animations:^{
        _keyBoardView.frame = CGRectMake(-1, kScreenHeight-200, kScreenWidth+2, 200);
    }];
}
- (void)notifinotshowAction{
    [UIView animateWithDuration:0.35 animations:^{
        _keyBoardView.frame = CGRectMake(-1, kScreenHeight+200, kScreenWidth+2, 200);
    }];
}

#pragma mark --- 创建tableView
- (void)createTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusHeight+kNavHeight, kScreenWidth, 150) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];
    
    [_tableView registerNib:[UINib nibWithNibName:@"QEditChargeCell" bundle:nil] forCellReuseIdentifier:@"QEditChargeCell"];
}

#pragma mark --- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    QEditChargeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QEditChargeCell" forIndexPath:indexPath];
    cell.style = QEditChargeCellStyleIncome;
    cell.indexPath = indexPath;
    cell.moneys = _str;
    cell.typeStr = _typeStr;
    cell.moneyStr = _moneyStr;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 0){
        [UIView animateWithDuration:0.35 animations:^{
            _keyBoardView.frame = CGRectMake(-1, kScreenHeight-200, kScreenWidth+2, 200);
        }];
        [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationKeyBoardShowB object:nil];
        [_textField resignFirstResponder];
        
    }else if (indexPath.row == 1){
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
        QEditChargeCell *cell = (QEditChargeCell *)[_tableView cellForRowAtIndexPath:indexPath];
        QIncomeChargeType *vc = [[QIncomeChargeType alloc] initWithBlock:^(NSString *str,NSString *typeId) {
            _typeStr = str;
            _typeId = typeId;
            cell.typeStr = _typeStr;
            CLog(@"收入文字---%@  收类型id---%@",_typeStr,_typeId);

        }];
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 2){
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
        QEditChargeCell *cell = (QEditChargeCell *)[_tableView cellForRowAtIndexPath:indexPath];
        QMoneyAccountVC *vc = [[QMoneyAccountVC alloc] initWithBlock:^(NSString *str,NSString *moneyId) {
            _moneyStr = str;
            _moneyId = moneyId;
            cell.moneyStr = _moneyStr;
            CLog(@"账户文字---%@  账户id---%@",_moneyStr,_moneyId);
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark----控件
- (void)createUI{
    _textField = [[UITextField alloc] initWithFrame:CGRectMake(15, _tableView.bottom+20, kScreenWidth-80, 40)];
    _textField.placeholder = @" 备注";
    _textField.font = [UIFont systemFontOfSize:Ksize15];
    _textField.borderStyle = UITextBorderStyleNone;
    _textField.text = _descStr;
    [_textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:_textField];
    
    UIImageView *imageLine = [[UIImageView alloc] initWithFrame:CGRectMake(15, _textField.bottom, kScreenWidth-80, 3)];
    imageLine.image = [UIImage imageNamed:@"textFieldLine_image"];
    [self.view addSubview:imageLine];
    
    UIButton *bacButton = [[UIButton alloc] initWithFrame:CGRectMake(15, imageLine.bottom+10, 120, 35)];
    bacButton.backgroundColor = [QColorUtility defaultLowGrayColor];
    bacButton.layer.cornerRadius = 5.0;
    bacButton.tag = 3;
    [bacButton addTarget:self action:@selector(bacButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bacButton];
    
    UIImageView *timeIconImage = [[UIImageView alloc] initWithFrame:CGRectMake(8, 11, 12, 12)];
    timeIconImage.image = [UIImage imageNamed:@"timeIcon_image"];
    [bacButton addSubview:timeIconImage];
    
    _timeLabel = [QViewUtility createLabelWithFrame:CGRectMake(timeIconImage.right+8, 0, 120-28, 35) font:13 textAlignment:NSTextAlignmentLeft textColor:[QColorUtility defaultBackColor] text:[NSString stringWithFormat:@"%@-%@ %@",_month,_day,_time]];
    [bacButton addSubview:_timeLabel];
    
    UIButton *leftButton = [QViewUtility createButtonWithFrame:CGRectMake(15, kScreenHeight-60, 100, 40) font:Ksize16 title:@"保存再记" titleColor:[UIColor grayColor] backgroundColor:[UIColor whiteColor]];
    leftButton.layer.cornerRadius = 4.0;
    leftButton.layer.borderColor = [UIColor grayColor].CGColor;
    leftButton.layer.borderWidth = 1;
    leftButton.tag = 1;
    [leftButton addTarget:self action:@selector(bacButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    UIButton *rightButton = [QViewUtility createButtonWithFrame:CGRectMake(leftButton.right+15, kScreenHeight-60,kScreenWidth-130-15, 40) font:Ksize16 title:@"保存" titleColor:[QColorUtility defaultBlueColor] backgroundColor:[UIColor whiteColor]];
    rightButton.layer.cornerRadius = 4.0;
    rightButton.layer.borderColor = [QColorUtility defaultBlueColor].CGColor;
    rightButton.layer.borderWidth = 1;
    rightButton.tag = 2;
    [rightButton addTarget:self action:@selector(bacButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightButton];
    
    if(_comeStyle == QIncomeVCHaveDataStyle){
        [leftButton setTitle:@"删除" forState:UIControlStateNormal];
    }else{
        [leftButton setTitle:@"保存再记" forState:UIControlStateNormal];
    }
}

- (void)textFieldAction:(UITextField *)textField{

    _descStr = textField.text;
}

#pragma mark----键盘显示
- (void)keyboardWillShow:(NSNotification *)notif{
    [UIView animateWithDuration:0.35 animations:^{
        _keyBoardView.frame = CGRectMake(-1, kScreenHeight+200, kScreenWidth+2, 200);
    }];
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationKeyBoardNotShowA object:nil];
}

#pragma mark----保存
- (void)bacButtonAction:(UIButton *)button{
    if(button.tag == 1){
        if(_comeStyle == QIncomeVCHaveDataStyle){       //删除->修
            _isBack = YES;
            BOOL flag = [QChargeBookDB deleteChargeBookDataWithaccountId:_accountIdStr];//删除返回肯定是有id
            if(flag){
                [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowData object:nil];
                [self writeData];//写入数据
            }else{
                [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:@"删除失败" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
            }
        }else{                                          //保存在记->增
            _isBack = NO;
            [self saveDataisSave:YES];
        }
    }else if (button.tag == 2){
        if(_comeStyle == QIncomeVCHaveDataStyle){       //保存->修
            _isBack = YES;
            [self saveDataisSave:NO];
        }else{                                          //保存->增
            _isBack = YES;
            [self saveDataisSave:YES];
        }
    }else if (button.tag == 3){
        QChooseDateVC *vc = [[QChooseDateVC alloc] initWithBlock:^(NSString *year, NSString *month, NSString *day, NSString *week, NSString *timeStamp,NSString *time) {
            CLog(@"年==%@  月==%@  日==%@  周==%@  时间戳==%@  时间==%@",year,month,day,week,timeStamp,time);
            _year = year; _month = month; _day = day; _week = week; _createTime = timeStamp; _time = time;
            _timeLabel.text = [NSString stringWithFormat:@"%@-%@ %@",_month,_day,_time];
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark----保存数据
- (void)saveDataisSave:(BOOL)isSave{
    if(_comeStyle == QIncomeVCHaveDataStyle){//说明是从有数据列表进来，不需要重新生成id
    }else{
        NSTimeInterval inter = [[NSDate date] timeIntervalSince1970] * 1000;//当前时间戳
        _accountIdStr = [NSString stringWithFormat:@"ios%.f",inter];
    }
    if(_str.length == 0 || [_str isEqualToString:@"0"] || [_str isEqualToString:@"0."] || [_str isEqualToString:@"0.0"] || [_str isEqualToString:@"0.00"] ){
        [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"请输入有效金额" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        return;
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict1 = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict3 = [NSMutableDictionary dictionary];
    
    [dict setObject:_accountIdStr forKey:@"accountId"];//数据的id
    [dict setObject:_year forKey:@"year"];//年
    [dict setObject:_month forKey:@"month"];//月
    [dict setObject:_week forKey:@"week"];//周
    [dict setObject:_day forKey:@"day"];//日
    [dict setObject:_time forKey:@"time"];//14：09时间
    [dict setObject:_createTime forKey:@"createTime"];//排序使用
    [dict setObject:_descStr forKey:@"remark"];//备注
    [dict setObject:@[] forKey:@"imgs"];
    
    [dict1 setObject:@"收入" forKey:@"accountName"];//支付和收入的类型
    [dict1 setObject:@"1" forKey:@"accountTypeId"];
    [dict1 setObject:_str forKey:@"money"];
    
    [dict2 setObject:_typeStr forKey:@"useTypeName"];//类型
    [dict2 setObject:_typeId forKey:@"useTypeId"];
    
    [dict3 setObject:_moneyStr forKey:@"moneyTypeName"];//账户
    [dict3 setObject:_moneyId forKey:@"moneyTypeId"];
    
    [dict setObject:dict1 forKey:@"accountTypeBean"];
    [dict setObject:dict2 forKey:@"accountUseTypeBean"];
    [dict setObject:dict3 forKey:@"accountMoneyTypeBean"];
    
    
    if(isSave){//新增的数据
        BOOL success = [QChargeBookDB saveChargeBookDataWithaccountId:_accountIdStr monthidStr:[NSString stringWithFormat:@"%@%@",_year,_month] createTime:_createTime dataDic:dict];
        if(success){
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowData object:nil];
            [self writeData];//写入数据
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:@"新增失败" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
            return;
        }
    }else{//修改数据
        BOOL fla = [QChargeBookDB updateSetDataWithaccountId:_accountIdStr dataDic:dict monthidStr:[NSString stringWithFormat:@"%@%@",_year,_month] createTime:_createTime];
        if(fla){
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowData object:nil];
            [self writeData];//写入数据
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:@"修改失败" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }
    }
}

#pragma mark----写配置文件
- (void)writeData{
    NSString *newYearMonth = [NSString stringWithFormat:@"%@%@",_year,_month];
    if(_comeStyle == QIncomeVCHaveDataStyle){//修改数据
        if([_yearMonthISeq isEqualToString:newYearMonth]){//如果修改的数据是同一个月只需要上传这个月的
            [self writeDataWithYearandMonth:newYearMonth];
        }else{//修改数据不是同一个月的则要上传这两个月的
            [self writeDataWithYearandMonth:newYearMonth];
            [self writeDataWithYearandMonth:_yearMonthISeq];
        }
    }else{//增加数据
        [self writeDataWithYearandMonth:newYearMonth];
    }
}

#pragma mark----写配置文件
- (void)writeDataWithYearandMonth:(NSString *)yearMonth{
    
    NSArray *monthDataArr = [QChargeBookDB queryMainPageWithMonthData:[NSString stringWithFormat:@"%@",yearMonth]];//一个月的数据
    NSMutableDictionary *writeDic = [NSMutableDictionary dictionary];
    [writeDic setObject:monthDataArr forKey:@"list"];
    NSString *dicStr = [QParamService dictToString:writeDic];
    NSData *jsonData = [dicStr dataUsingEncoding:NSUTF8StringEncoding];
    [self updateLoadData:jsonData fileName:[NSString stringWithFormat:@"accountFile%@",yearMonth] yearMonth:yearMonth type:@"1"];
    
    //写入配置文件
    NSTimeInterval inter = [[NSDate date] timeIntervalSince1970] * 1000;
    NSString *time = [NSString stringWithFormat:@"%.f",inter];
    [QChargeBookDB writeProfileByYearMonth:yearMonth time:time successBlock:^(NSString *arrf) {
        CLog(@"写入配置文件成功");
        NSData *data = [QChargeBookDB submitProfileDataToSever:arrf];
        [self updateLoadData:data fileName:@"accountSetting" yearMonth:yearMonth type:@"2"];
    }];
}

//上传
- (void)updateLoadData:(NSData *)data fileName:(NSString *)fileName yearMonth:(NSString *)yearMonth type:(NSString *)type{
    NSString *newYearMonth = [NSString stringWithFormat:@"%@%@",_year,_month];

    addIndex = 0;
    NSString *url = [QParamService urlWithAction:@"customerBilling"];
    NSDictionary *param = [QParamService upLoadDatayearMonth:[NSString stringWithFormat:@"%@_%@",_year,_month] type:type fileName:fileName];
    [QViewUtility showMBHudToView:self.view hideBg:NO];
    [[QHttpManager sharedManager] upLoadData:url params:param data:data fileName:fileName completion:^(NSData *data, NSDictionary *dict, NSError *error) {
        [QViewUtility hideMBHudToView:self.view];
        if(error){
            return ;
        }
        QBaseModel *basModel = [QBaseModel objectFromDict:dict];
        if([basModel.result isEqualToString:@"success"]){
            addIndex++;
            if(_comeStyle == QIncomeVCHaveDataStyle){//修改
                if([_yearMonthISeq isEqualToString:newYearMonth]){
                    if(addIndex == 2){
                        [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"上传成功" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
                        if(_isBack){
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                    }
                }else{
                    if(addIndex == 4){
                        [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"上传成功" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
                        if(_isBack){
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                    }
                }
            }else{
            
                if(addIndex == 2){
                    [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"上传成功" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
                    if(_isBack){
                        [self.navigationController popViewControllerAnimated:YES];
                    }
                }
            }
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:basModel.errMsg btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }
    }];
}

#pragma mark----键盘输出
- (void)keyboardIndex:(NSInteger)index{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    QEditChargeCell *cell = (QEditChargeCell *)[_tableView cellForRowAtIndexPath:indexPath];
    switch (index) {
        case 0:
        case 1:
        case 2:
        case 4:
        case 5:
        case 6:
        case 8:
        case 9:
        case 10:
        case 12://点
        case 13://0
            [self isMoreD:index];
            break;
        case 14:
        {
            QInputMoneyVC *vc = [[QInputMoneyVC alloc] init];
            vc.block = ^(NSString *str){
                _str = str;
                cell.moneyLabel.text = _str;
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 16://删除
        {
            c=[NSMutableString stringWithString:cell.moneyLabel.text];
            if([c isEqualToString:@"0.00"]){
                _str = @"";
            }else{
                [c  deleteCharactersInRange:NSMakeRange(c.length-1,1)];
                cell.moneyLabel.text=c;
                _str = c;
                if (cell.moneyLabel.text.length==0) {
                    cell.moneyLabel.text=@"0.00";
                    _str = @"";
                }
            }
        }
            break;
        case 17:
        {
            [UIView animateWithDuration:0.35 animations:^{
                _keyBoardView.frame = CGRectMake(-1, kScreenHeight+200, kScreenWidth+2, 200);
            }];
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationKeyBoardNotShowB object:nil];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark----输入处理
- (void)isMoreD:(NSInteger)index{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    QEditChargeCell *cell = (QEditChargeCell *)[_tableView cellForRowAtIndexPath:indexPath];
    
    if(_str.length > 0){
        _str = [_str stringByAppendingString:_titleArr[index]];
        cell.moneyLabel.text = _str;
        if(_str.length == 2 && [_str isEqualToString:@"00"]){
            _str = @"0";
            cell.moneyLabel.text = _str;
        }
    }else{
        _str = [_str stringByAppendingString:_titleArr[index]];
        if(_str.length == 2 && [_str isEqualToString:@"00"]){
            _str = @"0";
        }
        if(_str.length == 1 && [_str isEqualToString:@"."]){
            _str = @"0.";
        }
        cell.moneyLabel.text = _str;
    }
    
    NSArray *arr = [cell.moneyLabel.text componentsSeparatedByString:@"."];
    if(arr.count){//长度的限制
        NSString *s = arr[0];
        if(s.length>10){
            c=[NSMutableString stringWithString:cell.moneyLabel.text];
            [c  deleteCharactersInRange:NSMakeRange((c.length-1),1)];
            _str = c;
            cell.moneyLabel.text=c;
        }
    }
    
    NSInteger count=[arr count]-1;//去点
    if (count>1) {
        c=[NSMutableString stringWithString:cell.moneyLabel.text];
        [c  deleteCharactersInRange:NSMakeRange((c.length-1),1)];
        _str = c;
        cell.moneyLabel.text=c;
    }
    
    if([cell.moneyLabel.text containsString:@"."]){//保留小数点后面的
        NSArray *arrs = [cell.moneyLabel.text componentsSeparatedByString:@"."];
        if(arrs.count){
            NSString *s = arrs[1];
            if(s.length > 2){
                c=[NSMutableString stringWithString:cell.moneyLabel.text];
                [c  deleteCharactersInRange:NSMakeRange((c.length-1),1)];
                _str = c;
                cell.moneyLabel.text=c;
            }
        }
    }
}

#pragma mark----赋值年月日
- (void)formatDate:(NSString *)str{
    [QChargeBookDB formatDate:str successBlock:^(NSString *y, NSString *m, NSString *d, NSString *t) {
        _year = _year?_year:y;
        _month = _month?_month:m;
        _day = _day?_day:d;
        _time = _time?_time:t;
    }];
}

@end
